#ifndef RTARG_H_
#define RTARG_H_

#include "vmath/vmath.h"
#include "opengl.h"

namespace goatgfx {

class Texture;

class RenderTarget {
private:
	int width, height;

	unsigned int fbo;
	Texture *color_tex;
	unsigned int tex_targ;
	int tex_face;
	unsigned int rbuf_zstencil;

public:
	RenderTarget();
	~RenderTarget();

	bool create(unsigned int fmt = GL_RGBA);
	bool create(int width, int height, unsigned int fmt = GL_RGBA);
	bool create(Texture *tex, int face = 0);

	void cleanup();

	bool resize(int width, int height);

	int get_width() const;
	int get_height() const;

	Texture *get_texture() const;

	/** calculates a texture matrix to map the full texture space
	 * onto the part of the texture occupied by the render target
	 */
	Matrix4x4 get_texture_matrix() const;

	bool check() const;
	void bind() const;
};

void set_render_target(const RenderTarget *rtarg);

int next_pow2(int x);

}	// namespace goatgfx

#endif	// RTARG_H_
